package acm.pta7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 * @author 邢兵
 * @data
 * @description
 */
public class Test {
    public static int x;
    public static int max=1;
    public static Vector<Integer> G[] = new Vector[100001];
    public static int level[] = new int[100001];
    public static void main(String[] args) throws NumberFormatException, IOException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        //初始化数组避免出现nullpointexception
        for(int i=0;i<G.length;i++){
            G[i] = new Vector<Integer>();
        }
        for(int i=1;i<=n;i++){
            int t = in.nextInt();
            if(t==-1){
                x = i;
                level[i] = 1;
                continue;
            }
            G[t].add(i);
        }
        bfs();
        int flag = 0;
        System.out.println(max);
        for(int i=1;i<=n;i++){
            if(level[i]==max){
                if(flag==0){
                    System.out.print(i);
                    flag = 1;
                }else{
                    System.out.print(" "+i);
                }
            }
        }
    }
    public static void bfs(){
        LinkedList<Integer> list = new LinkedList<Integer>();
        list.add(x);
        while(!list.isEmpty()){
            int y = list.getFirst();
            list.removeFirst();
            for(int i=0;i<G[y].size();i++){
                int u = G[y].get(i);
                list.add(u);
                level[u] = level[y]+1;
                max = Math.max(max, level[u]);
            }
        }
    }
}
